import { useState } from 'react';
import { makeFacade, MessageFacade } from '@/facade/messageFacade';
import { MessageItem } from '@/models/Message';
import { useObservable } from '@/utils/rxHelpers';

export type MessageHookTuple = [MessageFacade, MessageItem[], MessageItem[], boolean, string, string, Record<string, any>];

//需要在页面用到的变量都在这里hook
export function useMsgFacade(): MessageHookTuple {
  const [msgFacade] = useState(() => makeFacade());

  const [isSDKReady] = useObservable(msgFacade.isSDKReady$, false);
  const [groupId] = useObservable(msgFacade.groupId$, '');
  const [enterMsg] = useObservable(msgFacade.enterMsg$, '');
  const [notifyMsg] = useObservable(msgFacade.notifyMsg$, {});
  const [msgList] = useObservable(msgFacade.msgList$, []);
  const [tuwenMsgList] = useObservable(msgFacade.tuwenMsgList$, []);

  return [msgFacade, msgList, tuwenMsgList, isSDKReady, groupId, enterMsg, notifyMsg];
}
